using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Markup;
using Rhizome.Contract;
using Rhizome.Contract.Visitor;
using Rhizome.Internal;

namespace Rhizome.Model
{
    [ContentProperty("Actions")]
	public sealed class MultiAction : ActionBase<object>, IForwardEvent
    {
        public MultiAction(params IAction[] actions) : this()
        {
        	if (actions == null) return;
        	
			foreach (var action in actions)
        		Actions.Add(action);
        }

    	public MultiAction()
        {
            Actions = new RhizomeElementCollection<IAction>(this);
        }

        public Collection<IAction> Actions { get; private set; }

        public override void Process()
        {
            Actions.ForEach(action => action.Process());
        }

    	#region Implementation of IForwardEvent

    	object IForwardEvent.GetForwardEvent()
    	{
    		return Actions.GetForwardEvent();
    	}

    	#endregion

    	#region Overrides of RhizomeElement

    	protected override IEnumerable<IEnumerable> GetElementCollections()
    	{
    		return base.GetElementCollections().Concat(new[] {Actions});
    	}

    	#endregion
    }
}